package com.ikkong.system.Util;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by Administrator on 2018-09-06.
 */
public class CommonUtil {

    public static Double money(double danjia,int kai,int num,int zhang,int jiqi){
        int k = 0;
        int j = 0;
        if(jiqi == 8){
            j=15;
            k = 90;
        }else if(jiqi == 4){
            j=25;
            k = 150;
        }else if(jiqi == 2){
            j=50;
            k = 200;
        }

        double b1 = (num-2000)*0.005/8;
        double b2 = (num/zhang-1000)/1000;
        double a1 = Math.ceil(b1);
        double a2 = Math.ceil(b2);

        double money = num*danjia/kai + ((double)70/jiqi + a1)*danjia+(k+a2*j);


        return money;
    }

    public static int jisuan(int bigx,int bigy){

        int x = 90;
        int y = 54;
        int numa = bigx/x;
        int shu = bigy/y;
        int maxnumy = bigy / x;
        int[] arr = new int[shu+1];



        for(int i = 0;i<=bigy /y;i++){
            int heng = i;//横着放i排
            int maxshu = (bigy - y*heng)/y;//竖着最多能放maxshu排

            int numheng = bigx  / x;
            numheng = numheng * heng;//横放几个
            int numshu = bigx/y;
            numshu =numshu * maxshu;//竖放几个

            int shenx = bigx%x;//横向取余
            int add = 0;

            //右上方剩余
            if (shenx > 0) {
                if(shenx<y){
                    add = bigy%x==0?bigy/x:bigy/x+1;
                    if(i%5!=0 && i>0){
                        add = add + 1;
                    }
                }else  {
                    add = bigy%y==0?bigy/y:bigy/y+1;
                }
            }

            int sheny = bigy - maxshu * y;//竖向还剩下多少

            //下方剩余
            if(0<sheny && sheny<y){
                add = bigx%x==0?bigx/x:bigx/x+1;
            }



//            sheny = sheny/y;
//            int maxshen = shenx * sheny;
            int max = numheng + numshu +add ;
            arr[i] = max==0?9999:max;
        }
        Arrays.sort(arr);
        return arr[0];


    }
}
